<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>表单模型配置</title>
        <{$showjs}>
        <link rel="stylesheet" type="text/css" href="/Plug-in/ext/resources/css/xtheme-slate.css" />
        <{$ajax}>
        <link rel="stylesheet" type="text/css" href="../css/main1.css" />
        <style type=text/css>
               <!--
               .x-btn-left{
        background-position:2px 0;
               }
               .x-btn-over .x-btn-left{
        background-position:2px -63px;
               }
               .i_sx{background-image:url(../img/arrow_refresh_small.png) !important;}
               .i_cs{background-image:url(../img/application_form_add.png) !important;}
               .i_sc{background-image:url(../img/application_form_delete.png) !important;}
               .i_qk{background-image:url(../img/application_delete.png) !important;}
               .i_px{background-image:url(../img/sucaiwcom8170000bzc.gif) !important;}
               .x-grid-record-del{text-decoration:line-through;background:#FFF893;color:#000;}
               .x-grid-record-new{color:#00933B;}

        --> </style>
        <script type="text/javascript" src="/Plug-in/ext/Ext.grid.CheckColumn.js"></script>
        <script type="text/javascript">

            Ext.onReady(function(){
                var myMask = new Ext.LoadMask(Ext.getBody(), {
                    msg: '请稍候...'
                });
                var fm = Ext.form;
                var sm = new Ext.grid.CheckboxSelectionModel();
                var fields = [
                    sm,
                    {name: 'id', mapping : 'id'},
                    {name: 'fname', mapping : 'fname'},
                    {name: 'name', mapping : 'name'},
                    {name: 'type', mapping : 'type'},
                    {name : 'cfg', mapping : 'cfg'},
                    {name : 'xr', mapping : 'xr'},
                    {name : 'del',type:'int'},
                    {name : 'isnew',type:'int'}
                ];
                var store =  new Ext.data.JsonStore({
                    id:'store',
                    url: 'form_config.php',
                    fields: fields
                });
                var comboStore =  new Ext.data.JsonStore({
                    id:'comboStore',
                    url: 'form_config.php',
                    fields: ['name','value']
                });
                comboStore.load({params:{op: 'combo_store'}});
                var donotrender = new Ext.grid.CheckColumn({
                    header: "屏蔽列表显示",
                    dataIndex: 'xr',
                    width: 80
                });
                var delRender =  new Ext.grid.CheckColumn({
                    header:'删除',
                    dataIndex:'del',
                    width:50
                })
                var row_id=0;

                var cm = new Ext.grid.ColumnModel([
                    {
                        id : 'id',
                        header: "唯一编号",
                        dataIndex: 'id',
                        width: 80/*,
                           renderer:function(value,cellmeta,record,rowIndex){
                    return rowIndex+1;}*/

                    },{
                        id : 'fname',
                        header: "字段名",
                        dataIndex: 'fname',
                        width: 80
                    },{
                        id : 'name',
                        header: "表单名",
                        dataIndex: 'name',
                        width: 100,
                        editor: new fm.TextField({
                            allowBlank: false
                        })
                    },
                    {
                        id : 'type',
                        header: "类型",
                        dataIndex: 'type',
                        width: 130,
                        editor: new fm.ComboBox({
                            id : 'catalog',
                            name : 'catalog',
                            emptyText  :'选择一个类型',
                            fieldLabel : '类型',
                            allowBlank : true,
                            store:comboStore,
                            hiddenName : 'type',
                            selectOnFocus:true,
                            mode:'local',
                            readOnly :true,
                            displayField: "value",
                            valueField :'name',
                            forceSelection: true,
                            triggerAction: "all"
                        })
                    },{id : 'cfg', header: "配置完成", sortable: true,width:80, dataIndex: 'cfg',renderer:function(val){
                            return val==1?'<img src="../img/wrench.png" width="12">双击配置':'<img src="../img/wrench_orange.png" width="12">双击配置';
                        }},donotrender,
                    //删除
                    delRender
                
                ]);

                store.load({params:{op: 'formitem',tid:'<{$tid}>',lg:'<{$lg}>'}});
                var grid = new Ext.grid.EditorGridPanel({
                    id				 :'grid',
                    store            : store,
                    cm				 : cm,
                    sm				 : sm,
                    autoExpandColumn : 'name',
                    plugins			 : [donotrender,delRender],
                    region           : 'center',
                    frame			 : false,
                    clicksToEdit	 : 2,
                    ddGroup			 :'GridDD',
                    enableDragDrop 	 : true,
                    border			 : false,
                    title            : false,
                    tbar:[{xtype: 'button',text:'<{$tname}> - 表单配置[<{$sytable}>]',iconCls:'i_tablecfg'}],
                    listeners: {
                        'render': function(){
                            bbar2.render(this.tbar);
                        },
                        "beforeedit":{
                            fn: function(items){
                                row_id=items.row;
                            },
                            scope: this
                        },
                        "afterEdit": {
                            fn: function(items){
                                myMask.show();
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'items_config_save_ingrid',id:items.record.data.id,value:items.value,field:items.field},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            },
                            scope: this
                        }
                    },
                    viewConfig : {
                        forceFit :true,
                        getRowClass : function(record,rowIndex,rowParams,store){
                            //删除样式
                            if(record.data.del=='1'){
                                return 'x-grid-record-del';
                            }else if(record.data.isnew=='1'){
                                return 'x-grid-record-new';
                            }else{
                                return '';
                            }   
                        }
                    } 
                });
	
                grid.on('celldblclick', function(grid, row, col, e) { 
				 
                    //				var row = grid.getSelectionModel().getSelected(); 
                    //				alert(row.data.id);
                    var record = grid.getStore().getAt(row);   //Get the Record
                    var fieldName = grid.getColumnModel().getDataIndex(col); //Get field name
                    //
                    //alert(fieldName);
                    if(fieldName=='cfg'){
                        var data = record.get('id');
                        var pr=top.Ext.get(data);
                        if(pr){
                            pr.close();
                        }
                        top.xajax_loadUrl(record.get('fname')+'_'+record.get('type')+'_'+'字段配置','./form/fldcfg.php?op=cfg&id='+data,680,520,false,data)
                        // 	Ext.MessageBox.alert('show','当前选中的数据是'+data)
                    }else{
                        return true;}
		

                });
                bbar2 = new Ext.Toolbar({
                    renderTo:grid.tbar
                    ,items:['->',{
                            text:'刷新',iconCls:'i_sx',handler:function(){
                                myMask.show();
                                store.reload();
                                myMask.hide();
                            }
                        },'-',{
                            text:'自动初始化所有字段',iconCls:'i_cs',handler:function(){
                                myMask.show();
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'cs',tid:"<{$tid}>",lg:'<{$lg}>'},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            }
                        },'-',{
                            text:'初始化字段排序',iconCls:'i_px',handler:function(){
                                myMask.show();
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'pxcs',tid:"<{$tid}>",lg:'<{$lg}>'},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            }
                        },'-',{
                            text:'改变使用表清空现有字段',iconCls:'i_qk',handler:function(){
                                Ext.Msg.confirm('危险','您确定要清空现有字段？',function(a){
                                    if(a == 'yes'){
                                        myMask.show();
                                        Ext.Ajax.request({
                                            waitMsg:'正在提交....',
                                            method:'POST',
                                            params:{op:'qk',tid:"<{$tid}>",lg:'<{$lg}>'},
                                            url:'form_config.php',
                                            success:function(form, action) {
                                                store.removeAll() ;
                                                myMask.hide();
                                            },
                                            failure: function(form, action) {
                                            }
                                        });
                                    }
                                })
                            }
                        },{
                            text:'列表屏蔽',
                            iconCls:'i_sc',
                            handler:function(){
                                myMask.show();
                                var selections = grid.selModel.getSelections();
                                var prez = [];
                                for(i = 0; i< grid.selModel.getCount(); i++){
                                    prez.push(selections[i].json.id);
                                }
                                var encoded_array= Ext.encode(prez);
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'form_component_del',ids:encoded_array,field:'xr',val:1},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            }
                        },{
                            text:'列表显示',
                            iconCls:'i_sc',
                            handler:function(){
                                myMask.show();
                                var selections = grid.selModel.getSelections();
                                var prez = [];
                                for(i = 0; i< grid.selModel.getCount(); i++){
                                    prez.push(selections[i].json.id);
                                }
                                var encoded_array= Ext.encode(prez);
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'form_component_del',ids:encoded_array,field:'xr',val:0},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            }
                        },{
                            text:'删除',
                            iconCls:'i_sc',
                            handler:function(){
                                myMask.show();
                                var selections = grid.selModel.getSelections();
                                var prez = [];
                                for(i = 0; i< grid.selModel.getCount(); i++){
                                    prez.push(selections[i].json.id);
                                }
                                var encoded_array= Ext.encode(prez);
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'form_component_del',ids:encoded_array,field:'del',val:1},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            }
                        },{
                            text:'反删除',
                            iconCls:'i_sc',
                            handler:function(){
                                myMask.show();
                                var selections = grid.selModel.getSelections();
                                var prez = [];
                                for(i = 0; i< grid.selModel.getCount(); i++){
                                    prez.push(selections[i].json.id);
                                }
                                var encoded_array= Ext.encode(prez);
                                Ext.Ajax.request(
                                {
                                    waitMsg:'正在提交....',
                                    method:'POST',
                                    params:{op:'form_component_del',ids:encoded_array,field:'del',val:0},
                                    url:'form_config.php',
                                    success:function(form, action) {
                                        store.reload();
                                        myMask.hide();
                                    },
                                    failure: function(form, action) {
                                    }
                                }
                            );
                            }
                        }, '-'
                    ]
                });
                var viewport = new Ext.Viewport({
                    layout : 'fit',
                    items:[
                        grid
                    ]
                });
                donotrender.on('click',function(a,b,c){
                    myMask.show();
                    Ext.Ajax.request(
                    {
                        waitMsg:'正在提交....',
                        method:'POST',
                        params:{op:'items_config_save_ingrid',id:c.data.id,value:c.data[a.dataIndex],field:a.dataIndex},
                        url:'form_config.php',
                        success:function(form, action) {
                            store.reload();
                            myMask.hide();
                        },
                        failure: function(form, action) {
                        }
                    }
                );
                });
                delRender.on('click',function(a,b,c){
                    myMask.show();
                    Ext.Ajax.request(
                    {
                        waitMsg:'正在提交....',
                        method:'POST',
                        params:{op:'items_config_save_ingrid',id:c.data.id,value:c.data[a.dataIndex],field:a.dataIndex},
                        url:'form_config.php',
                        success:function(form, action) {
                            store.reload();
                            myMask.hide();
                        },
                        failure: function(form, action) {
                        }
                    }
                );
                });
                var ddrow = new Ext.dd.DropTarget(grid.getView().mainBody, {
                    ddGroup : 'GridDD',
                    copy:false,
                    notifyDrop : function(dd, e, data) {
			
                        var sm = grid.getSelectionModel();
                        var rows = sm.getSelections();
                        var param =rows[0].data;
                        //alert(param.id);
                        var cindex = dd.getDragData(e).rowIndex;
                        //alert(dd.getDragData(e).selections['id']);
                        myMask.show();
                        Ext.Ajax.request(
                        {
                            waitMsg:'正在提交....',
                            method:'POST',
                            params:{op:'px',nowid:param.id,wz:cindex,lg:'<{$lg}>'},
                            url:'form_config.php',
                            success:function(form, action) {
                                store.reload();
                                myMask.hide();
                            },
                            failure: function(form, action) {
                            }
                        }
                    );
                    }
                });
            });
        </script>
    </head>
    <body>

    </body>
</html>